package project.ia04.agents.studio;

import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.TickerBehaviour;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.lang.acl.ACLMessage;
import project.ia04.utils.Data;

public class NewTurnBehaviour extends TickerBehaviour {

	private int count = 0;
	
	public NewTurnBehaviour(final Agent a, final long period,int count) {
		super(a, period);
		this.count = count;
	}

	@Override
	protected void onTick() {
		if(count > 0){
			ACLMessage message = new ACLMessage(ACLMessage.REQUEST);
			AID[] aids = ((StudioAgent)myAgent).getStaffAgents();
			
			for (AID aid : aids) {
				message.addReceiver(aid);
			}
			
			message.setConversationId(Data.SECONDPHASE);
			this.myAgent.send(message);
			System.out.println("NewTurnBehaviour --> Send2StaffAgents");
			count--;
			((StudioAgent)myAgent).getCurrentGame().setProgress(((StudioAgent)myAgent).getCurrentGame().getProgress()+5);
			message = new ACLMessage(ACLMessage.INFORM);
			message.setConversationId(Data.PROGRESS);
			message.setContent(String.valueOf(((StudioAgent)myAgent).getCurrentGame().getProgress()));
			message.addReceiver(((StudioAgent)myAgent).getXAgent());
			myAgent.send(message);
		}
		else{
			System.out.println("NewTurnBehaviour --> End");
			this.stop();
		}
	}
}
